package com.mico.example.springboot.jpa.controller;

import com.mico.example.springboot.jpa.domain.User;
import com.mico.example.springboot.jpa.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by micocube
 * ProjectName: springboot-example
 * PackageName: com.mico.example.springboot.jpa.controller
 * User: micocube
 * Email: ldscube@gmail.com
 * CreateTime: 2019/2/25下午1:55
 * ModifyTime: 2019/2/25下午1:55
 * Version: 0.1
 * Description:
 **/
@RestController
public class UserController {
    @Autowired
    UserService userService;
    @GetMapping("/user/{userName}")
    public User getUserByName(@PathVariable String userName){
        User byUsername = userService.findByUsername(userName);
        return byUsername;
    }

    @GetMapping("/users")
    public Page<User> getUserByName(String userName,Integer page,Integer size){
        Page<User> byUsername = userService.findByUsername(userName,PageRequest.of(page,size));
        return byUsername;
    }


}
